//
//  ViewController.swift
//  SwiftDEMO
//
//  Created by J on 16/6/10.
//  Copyright © 2016年 J. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    

    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.fuck()
    }

    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        
    }
    
    
    
    
    dynamic func fuck(){
        print(1)

    }
 
}

extension UIViewController {

public override static func initialize() {
    struct Static {
        static var token: dispatch_once_t = 0
    }
    
    // 确保不是子类
    if self !== UIViewController.self {
        return
    }
    
    dispatch_once(&Static.token) {
        let originalSelector = Selector("fuck")
        let swizzledSelector = Selector("ThisviewDidLoad")
        
        let originalMethod = class_getInstanceMethod(ViewController.self, originalSelector)
        let swizzledMethod = class_getInstanceMethod(UIViewController.self, swizzledSelector)//交换oc分类中的方法
          method_exchangeImplementations(originalMethod, swizzledMethod);
    }

}
    
    dynamic  func fuck2(){
        self.fuck2()
        
        print(2)
    }
    

}
